package cipher

import (
	"bytes"
)

type Cipher interface {
	Encrypt() ([]byte, error)
	Decrypt() ([]byte, error)
}

// cbc加密要需要填充字节为block的整数倍
func PKCS7Padding(src []byte, blockSize int) []byte {
	if (1<<8) <= blockSize || 0 >= blockSize {
		panic("the block size pkcs7 can padding is (0~255] ")
	}
	length := blockSize - len(src)%blockSize
	//填充
	padding := bytes.Repeat([]byte{byte(length)}, length)

	return append(src, padding...)
}

// cbc解密之后需要把之前填充的字节去掉
func PKCS7UnPadding(origData []byte) []byte {
	length := len(origData)
	unpadding := int(origData[length-1])
	return origData[:(length - unpadding)]
}
